package cn.lili.controller.user.union;

import cn.lili.common.utils.ResultUtil;
import cn.lili.common.vo.PageVO;
import cn.lili.common.vo.ResultMessage;
import cn.lili.modules.member.entity.dos.Union;
import cn.lili.modules.member.entity.dos.UnionNotice;
import cn.lili.modules.member.entity.dto.UnionAddDTO;
import cn.lili.modules.member.entity.dto.UnionNoticeAddDTO;
import cn.lili.modules.union.service.UnionNoticeService;
import cn.lili.modules.union.service.UnionService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@Api(tags = "工会公告管理接口")
@RestController
@RequestMapping("/user/union/notice")
@RequiredArgsConstructor
@Validated
public class UnionNoticeController {

    private final UnionNoticeService unionNoticeService;

    @ApiOperation(value = "添加工会公告")
    @PostMapping(value = "/add")
    public ResultMessage<Object> add(@Valid @RequestBody UnionNoticeAddDTO unionNoticeAddDTO) {
        unionNoticeService.add(unionNoticeAddDTO);
        return ResultUtil.success();
    }


    @ApiOperation(value = "编辑工会公告")
    @PostMapping(value = "/edit")
    public ResultMessage<Object> edit(@Valid @RequestBody UnionNoticeAddDTO unionNoticeAddDTO) {
        unionNoticeService.edit(unionNoticeAddDTO);
        return ResultUtil.success();
    }


    @ApiOperation(value = "删除工会公告")
    @PostMapping(value = "/del")
    public ResultMessage<Object> del(@Valid @RequestBody UnionNoticeAddDTO unionNoticeAddDTO) {
        unionNoticeService.delete(unionNoticeAddDTO);
        return ResultUtil.success();
    }

    @ApiOperation(value = "获取工会分页列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "分页对象,含pageNumber(页号),pageSize(每页大小)", required = true, paramType = "query"),
            @ApiImplicitParam(name = "unionId", value = "工会ID", required = true,paramType = "query"),
    })
    @GetMapping(value = "/list")
    public ResultMessage<Page<UnionNotice>> getByPage(String unionId, PageVO page) {
        return ResultUtil.data(unionNoticeService.getByPage(unionId, page));
    }

    @ApiOperation(value = "根据ID获取工会信息")
    @ApiImplicitParam(name = "noticeId", value = "公告ID", required = true, paramType = "path", dataType = "String")
    @PutMapping(value = "/{noticeId}")
    public ResultMessage<UnionNotice> getUnionNoticeById(@Valid @PathVariable String noticeId) {
        return ResultUtil.data(unionNoticeService.getById(noticeId));
    }

}
